package main

import (
	"encoding/json"
	"encoding/xml"
	"fmt"
	"gopkg.in/yaml.v3"
	"strings"
)

type Person struct {
	Name string `json:"name" xml:"name,attr" yaml:"name"`
	Age  int    `json:"age" xml:"age" yaml:"age"`
}

func main() {
	p := Person{"Jack", 20}
	indent := strings.Repeat(" ", 4)
	// JSON
	fmt.Println("JSON:")
	data_json, _ := json.MarshalIndent(p, "", indent)
	fmt.Println(string(data_json))
	p2 := new(Person)
	json.Unmarshal(data_json, p2)
	fmt.Println("Person from JSON = ", *p2)
	// YAML
	fmt.Println("\nYAML:")
	data_yaml, _ := yaml.Marshal(p)
	fmt.Println(string(data_yaml))
	p3 := new(Person)
	yaml.Unmarshal(data_yaml, p3)
	fmt.Println("Person from YAML = ", *p3)
	// XML
	fmt.Println("\nXML:")
	data_xml, _ := xml.MarshalIndent(p, "", indent)
	fmt.Println(string(data_xml))
	p4 := new(Person)
	xml.Unmarshal(data_xml, p4)
	fmt.Println("Person from XML = ", *p4)
}
